<?php 
session_start();

include("../../conexion.php");
	require_once("../../includes/barramenu.php") ;
	require_once("../../includes/gridView.php")  ;
	require_once("../../includes/combo.php")  	 ;
	$oBarra = new BarraMenu() 				     ;
	$Grid1  = new GridView()					 ;
	$oCombo = new CmbList()  				     ;	
	
$numcarta  = $_REQUEST['numcarta'];	

$consulcartas = mysql_query("SELECT ingreso_cartas.*, DATE_FORMAT(STR_TO_DATE(ingreso_cartas.fec_ingreso,'%d/%m/%Y'),'%d/%m/%Y') AS fec_ingreso2 FROM ingreso_cartas WHERE ingreso_cartas.num_carta='$numcarta'", $conn) or die(mysql_error());
$rowcarta = mysql_fetch_array($consulcartas);

$numca = $rowcarta['id_remitente'];

$SQLCLIENTE = mysql_query("SELECT * FROM cliente WHERE cliente.numdoc='$numca'", $conn) or die(mysql_error());
$rowcliente = mysql_fetch_array($SQLCLIENTE);

$numcarta = $rowcarta['num_carta'];
$numcarta2 = substr($numcarta,5,6).'-'.substr($numcarta,0,4);
	
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ingreso de cartas</title>
<link href="../../includes/css/jquery-ui-notarios.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../../tcal.css" />
<link href="../../includes/css/jquery-ui-notarios.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../../includes/css/uniform.default.min.css" />
<link rel="stylesheet" type="text/css" href="../../tcal.css" />

<script type="text/javascript" src="../../tcal.js"></script> 
<script type="text/javascript" src="../includes/Mantenimientos.js"></script> 
<script src="../../includes/jquery-1.8.3.js"></script>
<script src="../../includes/js/jquery-ui-notarios.js"></script>
<script src="../../includes/jquery.uniform.min.js"></script>
<script src="../../includes/maskedinput.js"></script>
<script type="text/javascript" src="../../tcal.js"></script> 


<style type="text/css">
div.representante {
	background:#333333;
	border: 1px solid #333333;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px;
	-moz-box-shadow: 0px 0px 7px #000000;
	-webkit-box-shadow: 0px 0px 7px #000000;
	box-shadow: 0px 0px 7px #000000;
	width:638px;
	height:220px;
	position:absolute;
	left: 549px;
	top: 496px;
	margin-top: 15px;
	margin-left: -450px;
	opacity: 0.95;
	filter: "alpha(opacity=50)"; /* expected to work in IE 8 */
	filter: alpha(opacity=50);   /* IE 4-7 */
	zoom: 1;
}

div.allcontrata {width:600px; height:150px; overflow:auto;}
.titupatrimo {font-size: 12; font-style: italic; font-family: Calibri;}
.camposss {font-family: Calibri; font-style: italic; font-size: 14px; color: #333333; }

#cabecera{
	margin:0 auto;
	border: 2px solid #ddd; 
	border-radius: 10px; 
	padding: 2px; 
	box-shadow: #ccc 5px 0 5px;
	margin-bottom:0px;
	}

</style>
<script type="text/javascript">
$(document).ready(function(){ 

	 $("button").button();
	 $("#dialog").dialog();
	 $("input, textarea").uniform();
	 $( "#dialog:ui-dialog" ).dialog( "destroy" );
	 
	})
	
	jQuery(function($){
		$("#fecentrega").mask("99/99/9999",{placeholder:"_"});
		$("#horaentrega").mask("99:99 aa",{placeholder:"_"});
		$("#fecrecogio").mask("99/99/9999",{placeholder:"_"});
		
	});
	
	function fEdita(){ 
	
	editremitenteeee();
	ndireccion_remi();
	feditaCarta();
	 }

	function fElimina()
	{
		var _numcarta = document.getElementById('numcarta').value;
		if(confirm('eliminar datos de la carta notarial N. '+_numcarta+' ?'))
		{	fElimCarta(); }	
		else{return;}
	}

	function fini(){	document.getElementById('idzona').value = '<?php echo $rowcarta['zona_destinatario']; ?>';	}


	function fmuescontenido()
	{
		var divobs = $('<div id="div_ayudacarta" title="div_ayudacarta"></div>');
		$('<div id="div_ayudacarta" title="div_ayudacarta"></div>').load('CartasAyuda.php')
		.dialog({
						autoOpen: true,
						position :["center","top"],
						width   : 550,
						height  : 250,
						modal:false,
						resizable:false,
						buttons: [{id: "btnaceptar", text: "Aceptar",click: function() {pasadatos();$(this).dialog("destroy").remove(); }},
						{text: "Cancelar",click: function() { $(this).dialog("destroy").remove(); }}],
						title:'Ayuda Cartas'
						
						}).width(550).height(250);	
						$(".ui-dialog-titlebar").hide();		
	}

	function newParticipante()
	{
		$('<div id="div_newpartic" title="div_newpartic"></div>').load('NewRemitente.php')
		.dialog({
						autoOpen: true,
						position :["center","top"],
						width   : 720,
						height  : 350,
						modal:false,
						resizable:false,
						buttons: [{id: "btnAcepPartic2", text: "Aceptar",click: function() {evalGuardaParticipante();$(this).dialog("destroy").remove(); }},
						{text: "Cancelar",click: function() {$(this).dialog("destroy").remove(); }}],
						title:'Agregar participantes'
						
						}).width(720).height(350);	
						$(".ui-dialog-titlebar").hide();		
	}

	function fImprimir()
	{
		var _num_carta = document.getElementById('numcarta').value;
		if(_num_carta==''){alert('Debe guardar los datos primero');return;}
	
		var _usuario_imprime = '<?php echo $_SESSION["apepat_usu"].' '.$_SESSION["nom1_usu"]; ?>';
		var _nom_notario     = 'NOMBRE DEL NOTARIO';
	
		var _data = {
						num_carta       : _num_carta,
						usuario_imprime : _usuario_imprime,
						nom_notario     : _nom_notario
					}
		
		
		$.post("../../reportes_word/generador_cartas.php",_data,function(_respuesta){
						alert(_respuesta);
					});
			
	}


    function fShowDatosProvee(evento)
		{			
			var _numdoc		= document.getElementById('numdoc').value;
			var _remitente  = document.getElementById('remitente');
			var _direccion  = document.getElementById('direccion_remi');
			var _telefono   = document.getElementById('telefono');
			
			if(evento.keyCode==13) 
				{
					if(_numdoc==''){alert('Ingrese un numero de documento');return;}
					
					var _des = fShowAjaxDato('../includes/remitente.php?numdoc='+_numdoc);
					document.getElementById('remitente').value = _des;
					
					var _direcc = fShowAjaxDato('../includes/direccion.php?numdoc='+_numdoc);
					document.getElementById('direccion_remi').value=_direcc;
					
					var _telf = fShowAjaxDato('../includes/telefono.php?numdoc='+_numdoc);
					document.getElementById('telefono').value=_telf;
					
					if(_remitente.value==''){alert('No se encuentra registrado');
					$('#numdoc').val('');
					$('#remitente').val('');
					$('#direccion_remi').val('');
					$('#telefono').val('');
					return; }
				}
		}


function fVisualDocument()
	{
		var _numcarta = document.getElementById('muescarta').value;
		if(_numcarta == ''){alert('Debe guardar los datos primero');return;}
	
		var _usuario_imprime = '<?php echo $_SESSION["apepat_usu"].' '.$_SESSION["nom1_usu"]; ?>';
		var _nom_notario     = 'NOMBRE DEL NOTARIO';
		
		
//AjaxReturn('../../reportes_word/generador_permiviaje_interior.php?id_viaje='+_id_viaje+'&usuario_imprime='+_usuario_imprime+'&nom_notario='+_nom_notario);
		window.open("genera_carta.php?numcarta="+_numcarta+"&usuario_imprime="+_usuario_imprime+"&nom_notario="+_nom_notario);
			
	}
	
	
		function editremitenteeee()
	{
		valord=document.getElementById('nremitente').value;
	 	textod=valord.replace(/&/g,"*");
		document.getElementById('remitente').value=textod;
	}
	
		function ndireccion_remi()
	{
		valord=document.getElementById('ndireccion_remi').value;
	 	textod=valord.replace(/&/g,"*");
		document.getElementById('direccion_remi').value=textod;
	}

	
	
</script>
</head>
<body onLoad="fini();" style="font-size:62.5%;">
<div id="carta_content">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td width="24%">
     <?php
				$oBarra->Graba        = "1"            ;
				$oBarra->GrabaClick   = "fEdita();"    ;
				$oBarra->Impri        = "1"                   ;
				$oBarra->ImpriClick   = "fImprimir();"      ;
				$oBarra->clase        = "css"      		  ; 
				$oBarra->Show()  						  ; 
				?></td>
	<td width="76%"><div id="verdocumen"><button title="visualizar" type="button" name="btnver"    id="btnver" value="visualizar" onclick="fVisualDocument();" ><img align="absmiddle" src="../../images/block.png" width="15" height="15" />Ver</button></div></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr>
    <td colspan="2"><table  width="100%">
      <tr>
        <td width="14%"><span class="camposss">Nro carta:</span></td>
        <td width="16%"><input name="numcarta" type="hidden" id="numcarta" value="<?php echo $rowcarta['num_carta']; ?>" style="text-transform:uppercase" size="15" />
        <input name="muescarta" type="text" id="muescarta" value="<?php echo $numcarta2; ?>" style="text-transform:uppercase" size="15" /></td>
        <td width="17%"><span class="camposss">Responsable:</span></td>
        <td width="33%"><input name="idencargado" type="text" id="idencargado" style="text-transform:uppercase" value="<?php echo $rowcarta['id_encargado']; ?>" size="15" readonly="readonly" />
          <input name="encargado" type="hidden" id="encargado" value="<?php echo $rowcarta['des_encargado']; ?>" style="text-transform:uppercase" size="40" /></td>
        <td width="17%"><span class="camposss">Fecha ingreso:</span> </td>
        <td width="36%"><input name="fecingreso" type="text" id="fecingreso" value="<?php echo $rowcarta['fec_ingreso2']; ?>" style="text-transform:uppercase" size="15" class="tcal" /></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2">
    <fieldset>
    <legend><span class="camposss">Remitente</span></legend>
    <table  width="100%">
        <tr>
          <td width="14%"><span class="camposss">N. Documento :</span></td>
          <td width="37%"><input name="numdoc" type="text" id="numdoc" style="text-transform:uppercase" onkeypress="fShowDatosProvee(event);" value="<?php echo $rowcarta['id_remitente']; ?>" size="15" maxlength="8" /><a href="#" onClick="newParticipante();//fShowDatosProveeClick()"> <img src="../../images/search.png" width="15" height="15" alt="" /></a>
         </td>
          <td width="19%"><span class="camposss">Telefono:</span></td>
          <td width="30%"><input name="telefono" type="text" id="telefono" value="<?php echo $rowcarta['telf_remitente']; ?>" style="text-transform:uppercase" size="15" maxlength="200"  /></td>
        </tr>
        <tr>
          <td><span class="camposss">Remitente:</span> </td>
          <td colspan="3"><input name="nremitente" type="text" id="nremitente"  onKeyUp="editremitenteeee();"style="text-transform:uppercase" value="<?php $c_desc = $rowcarta['nom_remitente'];
		  $textorpat=str_replace("?","'",$c_desc);
		  $textoamperpat=str_replace("*","&",$textorpat);
		  echo strtoupper($textoamperpat); ?>" size="60" maxlength="400" />
          <input type="hidden"  name="remitente" id="remitente"/>          </td>
          </tr>
        <tr>
          <td><span class="camposss">Direccion:</span> </td>
          <td colspan="3"><input name="ndireccion_remi" type="text" id="ndireccion_remi"  onKeyUp="ndireccion_remi();" style="text-transform:uppercase" value="<?php $c_desc = $rowcarta['dir_remitente'];
		  $textorpat=str_replace("?","'",$c_desc);
		  $textoamperpat=str_replace("*","&",$textorpat);
		  echo strtoupper($textoamperpat); ?>" size="60" maxlength="2000" />
          <input type="hidden"  name="direccion_remi" id="direccion_remi"/> </td>
        </tr>
        </table>
    </fieldset>  
      </td>
    </tr>
  <tr>
    <td colspan="2">
    <fieldset>
    <legend><span class="camposss">Destinatario</span></legend>
    <table  width="100%">
        <tr>
          <td width="14%"><span class="camposss">Nombre:</span> </td>
          <td colspan="3"><input name="destinatario" type="text" id="destinatario" style="text-transform:uppercase" value="<?php echo $rowcarta['nom_destinatario']; ?>" size="60" maxlength="400" /></td>
          </tr>
        <tr>
          <td><span class="camposss">Dir. destino</span></td>
          <td colspan="3"><input name="dirdestino" type="text" id="dirdestino" style="text-transform:uppercase" value="<?php echo $rowcarta['dir_destinatario']; ?>" size="60" maxlength="2000" /></td>
          </tr>
        <tr>
          <td height="21"><span class="camposss">Zona:</span> </td>
          <td width="35%">
          <?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT ubigeo.coddis AS 'id', ubigeo.nomdis AS 'descripcion' FROM ubigeo
ORDER BY ubigeo.nomdis ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "descripcion";
			$oCombo->size       = "150"; 
			$oCombo->name       = "idzona";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//funcionprueba()";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
		  ?>
          <input name="zonadestinatario" type="hidden" id="zonadestinatario" /></td>
          <td width="20%"><!--Costo:--> </td>
          <td width="31%"><input name="costo" type="hidden" id="costo" value="<?php echo $rowcarta['costo']; ?>" style="text-transform:uppercase" size="15" /></td>
        </tr>
        </table>
    </fieldset>
    
    </td>
    </tr>
  <tr>
    <td colspan="2">
    </td>
    </tr>
  <tr>
    <td colspan="2" >
    <fieldset>
    <legend><span class="camposss">Diligencia</span></legend>
    <table  width="100%">
        <tr>
          <td width="14%"><span class="camposss">Fec. Diligencia:</span></td>
          <td width="16%"><input name="fecentrega" type="text" id="fecentrega" value="<?php echo $rowcarta['fec_entrega']; ?>" style="text-transform:uppercase" size="15" class="tcal" /></td>
          <td width="8%"><span class="camposss">Hora:</span> </td>
          <td width="23%"><input name="horaentrega" type="text" id="horaentrega" value="<?php echo $rowcarta['hora_entrega']; ?>" style="text-transform:uppercase" size="15" /></td>
          <td width="7%"><span class="camposss">Por:</span></td>
          <td width="32%"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT usuarios.loginusuario AS 'id' ,CONCAT(usuarios.apepat,' ',usuarios.apemat, ', ',usuarios.prinom) AS 'des' FROM usuarios
ORDER BY usuarios.apepat ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "150"; 
			$oCombo->name       = "empentrega";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectzona(this.value);";   
			$oCombo->selected   =  $rowcarta['emple_entrega'];
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
          </tr>
        </table>
    </fieldset>
    </td>
    </tr>
  <tr>
    <td width="183" height="30" valign="top" ><span class="camposss">Contenido:</span>
        <a href="#" onClick="fmuescontenido()"><img src="../../images/help.png" width="12" height="12" alt="" /></a>
        </td>
    <td width="1138" height="30" ><label for="contecarta"></label>
      <textarea name="contecarta" id="contecarta"  cols="110" rows="5" style="text-transform:uppercase;"><?php echo $rowcarta['conte_carta']; ?></textarea></td>
    </tr>
  <tr>
    <td height="30" colspan="2" ><fieldset>
      <legend><span class="camposss">CARGO DESTINATARIO</span></legend>
      <table  width="100%">
        <tr>
          <td width="14%"><span class="camposss">Recogio la carta:</span> </td>
          <td colspan="3"><input name="nomrecogio" type="text" id="nomrecogio" style="text-transform:uppercase" value="<?php echo $rowcarta['nom_regogio']; ?>" size="60" maxlength="400" /></td>
        </tr>
        <tr>
          <td><span class="camposss">Documento</span></td>
          <td width="35%"><input name="docrecogio" type="text" id="docrecogio" style="text-transform:uppercase" value="<?php echo $rowcarta['doc_recogio']; ?>" size="30" maxlength="40"/></td>
          <td width="20%"><span class="camposss">Dia:</span> </td>
          <td width="31%"><input name="fecrecogio" type="text" id="fecrecogio" value="<?php echo $rowcarta['fec_recogio']; ?>" style="text-transform:uppercase" size="15" class="tcal" /></td>
        </tr>
        <tr>
          <td><span class="camposss">Nro Fac/Bol:</span></td>
          <td><input name="factura" type="text" id="factura" value="<?php echo $rowcarta['fact_recogio']; ?>" style="text-transform:uppercase" size="30" maxlength="400" /></td>
          <td colspan="2"></td>
          </tr>
      </table>
    </fieldset></td>
    </tr>
  <tr>
    <td height="30" colspan="2" align="right" >&nbsp;</td>
  </tr>
</table>
</div>
</body>
</html>